<?php
/**
 * @package lib.famteam.phporm
 */
/**
 * @package lib.famteam.phporm
 * @author polikeiji
 *
 */
class ORMapperQueryWhere {

	private $_queryWhere;

    public function ORMapperQueryWhere() {
		$this->_queryWhere = new QueryWhere();
    }
    
    public function addAnd($whereObject) {
    		$queryWhere = &$this->_queryWhere;
    		$addQueryWhere = &$whereObject->_queryWhere;
    		if ($addQueryWhere->isNotEmptyQuery()) {
	    		$queryWhere->addAnd($addQueryWhere);
    		}
    }
    
    public function addOr($whereObject) {
    		$queryWhere = &$this->_queryWhere;
    		$addQueryWhere = &$whereObject->_queryWhere;
    		if ($addQueryWhere->isNotEmptyQuery()) {
	    		$queryWhere->addOr($addQueryWhere);
    		}
    }
    
    public function addEqualsNullAnd($fieldName) {
    	$queryWhere = $this->_queryWhere;
		$queryWhere->addEqualsNullAnd($fieldName);
		$this->_queryWhere = $queryWhere;
    }
    public function addNotEqualsNullAnd($fieldName) {
    		$queryWhere = $this->_queryWhere;
		$queryWhere->addNotEqualsNullAnd($fieldName);
		$this->_queryWhere = $queryWhere;
    }
    public function addEqualsNullOr($fieldName) {
    	$queryWhere = $this->_queryWhere;
		$queryWhere->addEqualsNullOr($fieldName);
		$this->_queryWhere = $queryWhere;
    }
    public function addNotEqualsNullOr($fieldName) {
    	$queryWhere = $this->_queryWhere;
		$queryWhere->addNotEqualsNullOr($fieldName);
		$this->_queryWhere = $queryWhere;
    }
    
    public function addEqualsAnd($fieldName, $value) {
    	$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				$queryWhere->addStringEqualsAnd($fieldName, $value);
				break;
			case "t":
				$queryWhere->addTimestampEqualsAnd($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericEqualsAnd($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addEqualsOr($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				$queryWhere->addStringEqualsOr($fieldName, $value);
				break;
			case "t":
				$queryWhere->addTimestampEqualsOr($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericEqualsOr($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addNotEqualsAnd($fieldName, $value) {
    		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				$queryWhere->addStringNotEqualsAnd($fieldName, $value);
				break;
			case "t":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericNotEqualsAnd($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addNotEqualsOr($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				$queryWhere->addStringNotEqualsOr($fieldName, $value);
				break;
			case "t":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericNotEqualsOr($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addLikeAnd($fieldName, $value) {
    		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
			case 'x':
				$queryWhere->addStringLikeAnd($fieldName, $value);
				break;
			case "t":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				trigger_error(ORMapperErrorMessages::FAULT_QUERY . ' (' . $fieldName . ': ' . $value . ')', E_USER_WARNING);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addLikeOr($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
			case "x":
				$queryWhere->addStringLikeOr($fieldName, $value);
				break;
			case "t":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_ERROR);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_ERROR);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addGreaterAnd($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_ERROR);
				break;
			case "t":
				$queryWhere->addTimestampGreaterAnd($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericGreaterAnd($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addGreaterOr($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "t":
				$queryWhere->addTimestampGreaterOr($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericGreaterOr($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addLessAnd($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "t":
				$queryWhere->addTimestampLessAnd($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericLessAnd($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addLessOr($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "t":
				$queryWhere->addTimestampLessOr($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericLessOr($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addGreaterEqualsAnd($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_ERROR);
				break;
			case "t":
				$queryWhere->addTimestampGreaterEqualsAnd($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericGreaterEqualsAnd($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addGreaterEqualsOr($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "t":
				$queryWhere->addTimestampGreaterEqualsOr($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericGreaterEqualsOr($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addLessEqualsAnd($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "t":
				$queryWhere->addTimestampLessEqualsAnd($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericLessEqualsAnd($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }
    public function addLessEqualsOr($fieldName, $value) {
		$queryWhere = $this->_queryWhere;
		switch (FieldLibrary::getFieldTypeString($fieldName)) {
			case "s":
				trigger_error(ORMapperErrorMessages::FAULT_QUERY, E_USER_WARNING);
				break;
			case "t":
				$queryWhere->addTimestampLessEqualsOr($fieldName, $value);
				break;
			case "id":
			case "i":
			case "d":
			case "b":
			default:
				$queryWhere->addNumericLessEqualsOr($fieldName, $value);
				break;
		}
		$this->_queryWhere = $queryWhere;
    }

    public function getWhereQueryObject() {
    		return $this->_queryWhere;
    }
}
?>
